package com.bdqn.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class OAuth2Utils {


    /**
     * 获取gitee用户的信息
     * @param access_token  token
     * @return
     * @throws Exception
     */
    public static JSONObject getGiteeUser(String access_token) throws Exception {
        Map<String, String> getUserMap = new HashMap<>();
        getUserMap.put("access_token",access_token);
        HttpResponse getUser = HttpUtils.doGet("https://gitee.com", "/api/v5/user", "get", new HashMap<>(), getUserMap);
        JSONObject jsonObject =null;
        if(getUser.getStatusLine().getStatusCode()==200){
           jsonObject = JSON.parseObject(EntityUtils.toString(getUser.getEntity()));
        }

        return jsonObject;
    }

}
